package com.shop.mms_client.repository;

import android.content.Context;
import androidx.lifecycle.LiveData;
import com.shop.mms_client.db.AppDatabase;
import com.shop.mms_client.db.dao.BlacklistDao;
import com.shop.mms_client.model.BlacklistItem;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class BlacklistRepository {
    private static BlacklistRepository instance;
    private final BlacklistDao blacklistDao;
    private final ExecutorService executorService;

    private BlacklistRepository(Context context) {
        AppDatabase db = AppDatabase.getInstance(context);
        blacklistDao = db.blacklistDao();
        executorService = Executors.newSingleThreadExecutor();
    }

    public static synchronized BlacklistRepository getInstance(Context context) {
        if (instance == null) {
            instance = new BlacklistRepository(context);
        }
        return instance;
    }

    public void insert(BlacklistItem item) {
        executorService.execute(() -> blacklistDao.insert(item));
    }

    public void delete(BlacklistItem item) {
        executorService.execute(() -> blacklistDao.delete(item));
    }

    public LiveData<List<BlacklistItem>> getAllItems() {
        return blacklistDao.getAllItems();
    }
} 